
import ip from 'ip'
import config from './webpack.dev.config'
import webpack from 'webpack'
import path from 'path'
import color from 'colors/safe'
import webpackDevServer from 'webpack-dev-server'
const complier = webpack(config);
import DefaultConfig from '../src/config.default'


let port = DefaultConfig.listen.port;
let hostStatus = DefaultConfig.listen.host == "0.0.0.0"
let host = DefaultConfig.listen.host == "0.0.0.0" ? ip.address() : DefaultConfig.listen.host
const options: webpackDevServer.Configuration = {
    // contentBase: path.join(__dirname, '../dist/'),
    static: {
        directory: path.join(__dirname, '../dist/')
    },
    hot: true,
    host: host,
    port: port,
}
complier.hooks.done.tap('MyPlugin', () => {
    console.clear()
    console.log(color.yellow("App running at:"))
    console.info("  http://localhost" + ':' + color.green(port + ''))
    if (hostStatus) {
        console.info('  http://' + host + ':' + color.green(port + ''))
    }
})
const server = new webpackDevServer(options, complier);
(async () => {
    await server.start();
})()
